package com.etc.dao.impl;

import java.util.List;

import com.etc.dao.ShopDao;
import com.etc.entity.Shop;
import com.etc.util.DBUtil;

/**
 * 
 * @ClassName: ShopDaoImpl 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author knowno  
 * @date 2022年3月4日 上午9:14:26 
 *
 */
public class ShopDaoImpl implements ShopDao {
	/**
	 * 增加商家（店铺）
	 * 
	 * @param Shop 商家对象
	 */
	@Override
	public boolean addShop(Shop shop) {
		String sql = "insert into tbl_shop values(null,?,?,?,?,?)";
		return DBUtil.exUpdate(sql, shop.getShopname(), shop.getShoppwd(), shop.getShopuser(), shop.getShopphone(),
				shop.getShopstate())>0;
	}

	/**
	 * 删除商家（店铺）
	 * 
	 * @param shopid 店铺Id
	 */
	@Override
	public boolean delShop(int shopid) {
		String sql = "delete from tbl_shop where shopid=?";
		return DBUtil.exUpdate(sql, shopid)>0;
	}

	/**
	 * 修改商家（店铺）的状态信息
	 * 
	 * @param shopid 店铺ID
	 * @param state  状态值
	 */
	@Override
	public boolean upDateShop(String shopname, int state) {
		String sql = "update tbl_shop set shopstate =? where shopname=?";
		return DBUtil.exUpdate(sql, state, shopname)>0;
	}

	/**
	 * 查询所有商家（店铺）信息
	 */
	@Override
	public List<Shop> queryAllShop() {
		String sql = "select * from tbl_shop";
		return (List<Shop>) DBUtil.exQuery(sql, Shop.class);
	}

	/**
	 * 查询某一个商家（店铺）的信息
	 * 
	 */
	@Override
	public Shop queryOneShop(int shopid) {
		String sql = "select * from tbl_shop where shopid = ?";
		List<Shop> list = (List<Shop>) DBUtil.exQuery(sql, Shop.class, shopid);
		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
	}
	/**
	 * 商家登录
	 */
	@Override
	public boolean shopLogin(String shopname, String shoppwd) {
		String sql = "select * from tbl_shop where shopuser = ? and shoppwd=? and shopstate=1";
		List<Shop> list = (List<Shop>) DBUtil.exQuery(sql, Shop.class, shopname, shoppwd);
		if (list.size() > 0)
			return true;
		return false;
	}

	@Override
	public List<Shop> selShopname(String shopname) {
		String sql = "select shopid,shopname,shopuser,shopphone from tbl_shop where shopname=?";
		List<Shop> list = (List<Shop>) DBUtil.exQuery(sql, Shop.class, shopname);
		if(list.size()>0)
			return list;
		return null;
	}
	
	/**
	 * 
	 */
	public Shop queryOneShop(String shopuser) {
		String sql = "select * from tbl_shop where shopuser = ?";
		List<Shop> list = (List<Shop>) DBUtil.exQuery(sql, Shop.class, shopuser);
		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
	}

	/**
	 * 
	 */
	@Override
	public boolean upDateShop(int shopid, String shopname, String shopphone) {
		String sql = "update tbl_shop set shopphone =?,shopname=? where shopid=?";
		return DBUtil.exUpdate(sql, shopphone, shopname,shopid)>0;
	}


}
